package middle

import (
	"github.com/gogf/gf/net/ghttp"
)

func start(r *ghttp.Request) *RunTime {
	return newRunTime(r)
}

func (this *RunTime) done() {
	printErr(this.do())
}

func (this *RunTime) do() error {
	if db != nil {
		s1 := this.end()
		printErr(insert(this.toLog()))
		return nil

		l := new(RunTime)
		has, err := db.Where("Method=?", this.Method).And("Url=?", this.Url).Get(l)
		if err != nil {
			return err
		} else if has {
			//更新次数,最大执行时间
			s2 := this.addCount(l.MaxSpend)
			_, err = db.ID(l.ID).Cols(s1, s2).Update(this)
			return err
		} else {
			return insert(this)
		}
	}
	return nil
}
